<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改会议记录')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />

    <style type="text/css">
        .imgDiv {
            display: inline-block;
            position: relative;
        }

        .imgDiv .deleteImg {
            position: absolute;
            top: -5px;
            right: 0px;
            width : 40px;
            height : 40px;
            display:none;
        }

        .showDiv {
            display: inline-block;
            position: relative;
        }

        .showDiv .showImg {
            position: absolute;
            top: -5px;
            right: 0px;
            width: 40px;
            height: 40px;
        }

    </style>

</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-record-edit" th:object="${record}">
        <input name="recordId" th:field="*{recordId}" type="hidden">
        <!--<div class="form-group">-->
            <!--<label class="col-sm-2 control-label">所属小组：</label>-->
            <!--<div class="col-sm-9">-->
                <!--<input name="deptId" type="hidden" th:field="*{deptId}" id="treeId"/>-->
                <!--<div class="input-group">-->
                    <!--<input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" id="treeName"-->
                           <!--th:field="*{deptName}" required>-->
                    <!--<span class="input-group-addon"><i class="fa fa-search"></i></span>-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
        <div class="form-group">
            <label class="col-sm-2 control-label">会议标题：</label>
            <div class="col-sm-9">
                <input name="recordTitle" th:field="*{recordTitle}" class="form-control" type="text" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">会议内容：</label>
            <div class="col-sm-9">
                <input id="recordContent" name="recordContent" th:field="*{recordContent}" class="form-control" type="hidden"
                          >
                <div id="editor" class="summernote"></div>
            </div>
        </div>
        <!--<div class="form-group">-->
            <!--<label class="col-sm-2 control-label">图片：</label>-->
            <!--<div class="col-sm-9">-->
                    <!--<button type="button" class="btn btn-primary" id="showBtn">上传图片</button>-->
                    <!--<input id="recordImg" name="recordImg" th:field="*{recordImg}" type="hidden" class="form-control">-->
                    <!--<div class="layui-upload-list" id="showPrew" style="padding:5px;"></div>-->
            <!--</div>-->
        <!--</div>-->
        <div class="form-group">
            <label class="col-sm-2 control-label">视频：</label>
            <div class="col-sm-9">
                <input id="recordVideo" name="recordVideo" th:field="*{recordVideo}" class="form-control" type="hidden">
                <div class="row">
                    <div id="photosDiv" class="col-sm-12" th:if="${videos!=null && #lists.size(videos)>0}">
                        <th:block th:each="name:${videos}">
                            <div class="">
                                <div  class="videoBox" >
                                    <div  class="" >
                                        <video th:src="${name}"  autoplay style='width:600px;height:500px;' ></video>
                                    </div>

                                </div>
                            </div>
                        </th:block>
                    </div>
                    <div class="col-sm-12" th:if="${videos==null || #lists.size(videos)<1}">
                        <span>暂无视频！</span>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">记录人姓名：</label>
            <div class="col-sm-9">
                <input name="userName" th:field="*{userName}" class="form-control" type="text" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">记录时间：</label>
            <div class="col-sm-9">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="recordTime" th:value="${#dates.format(record.recordTime, 'yyyy-MM-dd HH:mm:ss')}"
                           class="form-control" type="text" readonly>
                </div>
            </div>
        </div>


    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: summernote-js" />
<script type="text/javascript">
    var prefix = ctx + "module/record";
    $("#form-record-edit").validate({
        focusCleanup: true
    });

    /*用户管理-修改-选择部门树*/
    function selectDeptTree() {
        var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }


    $(function() {
        $('.summernote').summernote({
            placeholder: '请输入内容',
            height : 400,
            lang : 'zh-CN',
            followingToolbar: false,
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this);
                }
            }
        });
        var content = $("#recordContent").val();
        $('#editor').summernote('code', content);
    });

    // 上传文件
    function sendFile(file, obj) {
        var data = new FormData();
        data.append("file", file);
        $.ajax({
            type: "POST",
            url: ctx + "common/upload",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function(result) {
                if (result.code == web_status.SUCCESS) {
                    $(obj).summernote('editor.insertImage', result.url, result.fileName);
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function(error) {
                $.modal.alertWarning("图片上传失败。");
            }
        });
    }


    var picArr= new Array();

    var pic = $("#recordImg").val();
    if(null!=pic && pic.length>0){
        picArr = pic.split(",");
        for(var i=0;i<picArr.length;i++){
            $('#showPrew').append("<div class='imgDiv' id='"+i+"'><img src='"+picArr[i]+"' style='width:180px;height:180px;margin:20px;' onclick='previewImg(this)'><a href='#' onclick='removeImg("+i+")'><img src='../../../img/delete.png' class='deleteImg' th:src='@{/img/delete.png}' /></a></div>");

        }
    }

    //上传图片
    layui.use(['upload'], function () {
        var $ = layui.jquery
            , upload = layui.upload;

        var showUpload= upload.render({
            elem: '#showBtn'
            , url:  ctx + "common/uploadImage_QiNiu"
            , size: 10000
            ,multiple: true
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#showPrew').append("<div class='showDiv' id='"+i+"'><img src='"+result+"' style='width:180px;height:180px;margin:20px;' onclick='previewImg(this)'><a href='#' onclick='removeImg("+i+")'><img src='../../../img/delete.png' class='showImg'/></a></div>");
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                var picStr =  res.data.src;
                picArr.push(picStr);

                var pic = picArr.join(",");
                console.log("***"+pic);
                $("#recordImg").val(pic);

            },error:function () {
                //演示失败状态，并实现重传
                var demoText = $('#showText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    showUpload.upload();
                });
            }
        });
    });


    function removeImg(id) {
        $.modal.confirm("确认要删除选中的图片吗?", function() {
            $("#"+id).remove();
            picArr.splice(id,1); //删除图片数组中的图片
            var pic = picArr.join(",");
            console.log("Delete后***"+pic);
            $("#recordImg").val(pic);
        });

    }

    function previewImg(obj) {
        var img = new Image();
        img.src = obj.src;
        var imgHtml = "<img src='" + obj.src + "' width='600px' height='600px'/>";
        //弹出层
        layer.open({
            type: 1,
            shade: 0.8,
            offset: 'auto',
            area: [600 + 'px',600+'px'],
            shadeClose:true,
            scrollbar: false,
            title: "图片预览", //不显示标题
            content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            cancel: function () {
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
            }
        });
    }

    //鼠标划过事件
    $(".imgDiv").mouseover(function () {
        //显示删除叉
        $(this).find(".deleteImg").css("display", "block");
    });
    $(".imgDiv").mouseout(function () {
        //隐藏删除叉
        $(this).find(".deleteImg").css("display", "none");
    });

    //鼠标划过事件
    $(".showDiv").mouseover(function () {
        //显示删除叉
        $(this).find(".showImg").css("display", "block");
    });
    $(".showDiv").mouseout(function () {
        //隐藏删除叉
        $(this).find(".showImg").css("display", "none");
    });



    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }


    //上传图片
    var uploadUrl = ctx + "common/uploadImage_QiNiu";

    $(document).ready(function () {
        var recordImg = $("#recordImg").val();
        if (recordImg != null && recordImg != "") {
            var imgs = recordImg.split(',');
            console.log(imgs);
            $("#fileinput-demo-1").fileinput({
                'theme': 'explorer-fas',
                'uploadUrl': uploadUrl,
                overwriteInitial: false,
                allowedFileExtensions: ['jpg', 'png', 'gif'],//接收的文件后缀
                initialPreviewAsData: true,
                initialPreview: imgs
            });

        } else {
            $("#fileinput-demo-1").fileinput({
                'theme': 'explorer-fas',
                'uploadUrl': uploadUrl,
                overwriteInitial: false,
                allowedFileExtensions: ['jpg', 'png', 'gif'],//接收的文件后缀
                initialPreviewAsData: true,
                initialPreview: []
            });
        }

        var result = "";
        // 上传成功回调
        $("#fileinput-demo-1").on("fileuploaded", function (event, data, previewId, index) {
            result += data.response.data.src + ",";
            $("#recordImg").val(result);
            console.log(result);
        });

        // 上传成功回调
        $("#fileinput-demo-1").on("filesuccessremove", function(event, id) {
            console.log(id);

        });

    });

    //上传视频
    // $(document).ready(function () {
    //
    //     var recordVideo = $("#recordVideo").val();
    //     if (recordVideo != null && recordVideo != "") {
    //         var videos = recordVideo.split(',');
    //         console.log(videos);
    //         $("#fileinput-video").fileinput({
    //             'theme': 'explorer-fas',
    //             'uploadUrl': uploadUrl,
    //             overwriteInitial: false,
    //             allowedFileExtensions: ["mp4", "avi", "dat", "3gp", "mov", "rmvb"],
    //             initialPreviewAsData: true,
    //             initialPreview: videos
    //         });
    //     } else {
    //         $("#fileinput-video").fileinput({
    //             'theme': 'explorer-fas',
    //             'uploadUrl': uploadUrl,
    //             overwriteInitial: false,
    //             allowedFileExtensions: ["mp4", "avi", "dat", "3gp", "mov", "rmvb"],
    //             initialPreviewAsData: true,
    //             initialPreview: []
    //         });
    //     }
    //
    //     var result = "";
    //     // 上传成功回调
    //     $("#fileinput-video").on("fileuploaded", function (event, data, previewId, index) {
    //         console.log(data);
    //         result += data.response.data.src + ",";
    //         $("#recordVideo").val(result);
    //
    //     });
    // });

    function submitHandler() {
        if ($.validate.form()) {
            var sHTML = $('.summernote').summernote('code');
            $("#recordContent").val(sHTML);
            //$.operate.save(prefix + "/edit", $('#form-record-edit').serialize());
            $.modal.close();
        }
    }
</script>
</body>
</html>